import request from "@/utils/request"

//1,基础销售属性的某一个类型
export interface BaseSaleAttrItemType {
    id?: number;
    name: string;
}

//1.1基础销售属性列表类型
export type BaseSaleAttrListType = BaseSaleAttrItemType[]

//3.1 spu图片列表的某一类型
export interface SpuImageItemType {
    id?: number;
    imgName: string;
    imgUrl: string;
    spuId?: number;
}
//spu图片列表的类型
export type SpuImageListType = SpuImageItemType[]

//3.2.1 spu销售属性值列表中某一项的类型
export interface SpuSaleAttrValueItemType {
    baseSaleAttrId?: number;
    id?: number;
    isChecked: string;
    saleAttrName: string;
    saleAttrValueName: string;
    spuId?: number;
}

//3.2.2 spu销售属性值列表类型
export type SpuSaleAttrValueListType = SpuSaleAttrValueItemType[]

//3.2 spu销售属性列表中的某一类型
export interface SpuSaleAttrItemType {
    baseSaleAttrId?: number;
    id?: number;
    saleAttrName: string;
    spuId?: number;
    spuSaleAttrValueList: SpuSaleAttrValueListType;

}

//3.3 spu销售属性列表类型
export type SpuSaleAttrListType = SpuSaleAttrItemType[]



//3,一个完整的spu信息类型
export interface SpuInfoType {
    category3Id?: number;
    description: string;
    id?: number | null;
    spuImageList: SpuImageListType | null;
    spuName: string;
    spuSaleAttrList: SpuSaleAttrListType | null;
    tmId?: number | null;
}

//5,分页列表返回值的类型
export interface SpuPageListReturnType {
    records: SpuInfoType[];
    total: number;
    size: number;
    current: number;
    searchCount: boolean;
    pages: number;
  }


//1,请求spu所有的销售属性列表
export const requestBaseSaleAttrList = () => {
    return request.get<any, BaseSaleAttrListType>(`/admin/product/baseSaleAttrList`)
}

//2,根据spuId删除spu
export const requestDeleteSpu = (spuId: number) => {
    return request.delete<any, null>(`/admin/product/deleteSpu/${spuId}`)
}

//3,新增Spu
export const requestSaveSpuInfo = (SpuInfo:SpuSaleAttrListType) => {
    request.post<any, null>(`/admin/product/saveSpuInfo`, SpuInfo)
}

//4,修改spu
export const requestUpdateSpuInfo = (SpuInfo:SpuSaleAttrListType) => {
    request.post<any, null>(`/admin/product/updateSpuInfo`, SpuInfo)
}

//5,分页
export const requestSpuPageList = (
    page: number,
    limit: number,
    category3Id: number,
) => {
    return request.get<any, SpuPageListReturnType>(
        `/admin/product/${page}/${limit}?category3Id=${category3Id}`
    )

}

//6,根据spuId获取Spu图片列表
export const requestSpuImgList = (spuId: number) => {
    return request.get<any, SpuImageListType>(
      `/admin/product/spuImageList/${spuId}`
    );
  };


//根据spuId获取当前spu的销售属性
export const requestSpuSaleAttrList = (spuId: number) => {
    return request.get<any, SpuSaleAttrListType>(
      `/admin/product/spuSaleAttrList/${spuId}`
    );
  };